<?php

//Yii::import('zii.widgets.jui.CJuiDialog');

class Dialog extends CWidget
{
	public $id;
	public $div;
	public $url;
	public $options;

	public function run()
	{
		Yii::app()->clientScript->registerScript($this->div, 
"jQuery.ajax({
	'beforeSend':function(){ $('#$this->div').parent().find('div.loading').show()},
	'url':'$this->url',
	'cache':false,
	'success':function(html){jQuery('#$this->div').html(html)},
	'error':function(XMLHttpRequest, textStatus, errorThrown){jQuery('#$this->div').html(textStatus)},
	'complete':function(){ $('#$this->div').parent().find('div.loading').hide()},
});");
		//echo CHtml::openTag('div',array('class'=>'loading'));
		//echo CHtml::image(Yii::app()->theme->baseUrl.'/css/loading.gif');
		//echo Chtml::closeTag('div')."\n";
		//echo CHtml::openTag('div',array('id'=>$this->div))."\n";
		//echo Chtml::closeTag('div')."\n";
		
		//$this->render('dialog', array(
		//	'options'=>$this->options,
		//	'id'=>$this->id,
		//	'div'=>$this->div,
		//));
		
		$this->beginWidget('zii.widgets.jui.CJuiDialog', array(
			'id'=>$this->id,
			// additional javascript options for the dialog plugin
			'options'=>$this->options,
			'themeUrl'=>Yii::app()->theme->baseUrl.'/css',
			'theme'=>'smoothness',
		));
 
echo CHtml::openTag('div',array('class'=>'loading'));
echo CHtml::image(Yii::app()->theme->baseUrl.'/css/loading.gif');
echo Chtml::closeTag('div')."\n";
echo CHtml::openTag('div',array('id'=>$this->div))."\n";
echo Chtml::closeTag('div')."\n";
 
		$this->endWidget('zii.widgets.jui.CJuiDialog');
	}
}